package com.server.core.util;

import com.server.core.domain.Result;
import org.json.JSONObject;

public class JsonUtil {

    public static  String convert(Object object) {
        JSONObject jsonObject = new JSONObject(object);
        return jsonObject.toString();
    }
    /**
     * @description 简单的返回值构造器
     * @author Alllen
     * @date   19/06/14
     */
    public enum ResultGenerator {

        OK(200,"ok"),


        FORBIDDEN(403, "缺权限，操作被禁止"),


        ERROR(500, "服务器发生无法预期的错误，请联系管理员"),


        NOT_FOUND(404, "资源未找到"),


        TOKEN_NOT_FOUND(401,"token错误或已过期"),


        LACK_TOKEN(401, "缺乏token"),


        ERROR_URL(400, "请求url或相关参数出错，请参照文档进行请求")
        ;


        public Result result;
        ResultGenerator(int code, String msg){
             result = new Result(code, msg);
        }

        public Result getResult() {
            return result;
        }

        public void setResult(Result result) {
            this.result = result;
        }

        @Override
        public String toString() {
            return result.toString();
        }
    }
}
